<?php


class loginClass {
    private $userName,$password,$usID,$stID,$db;
    
    function __construct($userName, $password) {
       //set data
       $this->setData($userName, $password);
        //connect to db
        $this->connectDB();
        //get data
        $this->getData();
    }
    private function setData($userName,$password){
        $this->userName=$userName;
        $this->password=$password;
        $this->stID=NULL;
        $this->usID=NULL;
        
    }
     private function connectDB(){
        
      try {
          include 'database.php';
     $db_config_file="db_config.php";
     $this->db=new database($db_config_file);
}   
       catch (Exception $ex) {
       $ex->getMessage(); 
}
  
    }
    function getUser(){
        if($this->stID!=NULL and $this->stID!=NULL)
        {
            $result['usID']=  $this->usID;
            $result['stID']=  $this->stID;
            return $result;
            
        }
    }

    private function getData(){
        $sql="select * from user where email='$this->userName' and pass='$this->password'";
        $result=mysql_query($sql);
        if($result)
        {
            $num=  mysql_num_rows($result);
            $row=  mysql_fetch_array($result);
            if($num>0)
            {
                $this->stID=$row['userID'];
                $this->stID=$row['stID'];
                return TRUE;
                
            }
       else {
     
                throw  new Exception("error 1:email or password is invalid");
            }
            
           
        }
        else{
            throw new Exception("error 2:email or password is invalid");
        
        }
    }
    private function close(){
        
        $this->db->close();
    }
    
}

?>